package ui;

import io.DataAccess;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.TitledBorder;

import java.awt.GridLayout;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.util.Iterator;
import java.util.List;
import javax.swing.border.EmptyBorder;

public class UserPanel extends JPanel {

  private JTable table;
  
  /**
   * Create the panel.
   */
  public UserPanel() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    
    DataAccess da = new DataAccess();
    List[] users = da.getAllUserData();
    String[] headers = {"ID", "First Name", "Last Name", "Email", "Conference ID", "Conference Title", "Role ID", "Conference Description", "Role"};
    String[][] data = new String[users.length][headers.length];
    for (int i = 0; i < users.length; i++) {
      List<String> user = users[i];
      Iterator<String> itr = user.iterator();
      int j = 0;
      while (itr.hasNext()) {
        data[i][j++] = itr.next();
      }
    }
    boolean[] bools = {false, false, false, true, false, true};
    table = new CustomTable(data, headers, bools);
    
    add(table.getTableHeader());
    JScrollPane sp = new JScrollPane(table);
    sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    add(sp);
  }

}
